package cn.cqautotest.cqviehelper.ui.activity;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable;
import android.os.Environment;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.biometric.BiometricManager;
import androidx.biometric.BiometricPrompt;
import androidx.core.content.ContextCompat;

import com.airbnb.lottie.LottieAnimationView;
import com.blankj.utilcode.util.ThreadUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;

import cn.cqautotest.cqviehelper.R;
import cn.cqautotest.cqviehelper.base.BaseActivity;
import cn.cqautotest.cqviehelper.base.ChangeSkinActivity;
import cn.cqautotest.cqviehelper.config.AppConfig;

import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.gyf.immersionbar.BarHide;
import com.gyf.immersionbar.ImmersionBar;
import com.vondear.rxtool.RxTool;

import java.io.File;
import java.util.concurrent.Executor;

import butterknife.BindView;
import cn.cqautotest.cqviehelper.config.SkinConstants;
import cn.cqautotest.cqviehelper.skin.SkinManager;
import cn.cqautotest.cqviehelper.skin.callback.ISkinChangingCallback;
import cn.cqautotest.cqviehelper.ui.dialog.ToastDialog;
import cn.cqautotest.cqviehelper.utils.LogUtils;
import cn.cqautotest.cqviehelper.utils.StringJoinUtils;

/**
 * author : anjiemo
 * github : https://gitee.com/anjiemo/CqvieHelper
 * time   : time   : 2020/03/02
 * desc   : 闪屏界面
 */
@SuppressLint("NonConstantResourceId")
public final class SplashActivity extends ChangeSkinActivity implements ISkinChangingCallback {

    @BindView(R.id.iv_splash)
    ImageView mIvSplashView;
    @BindView(R.id.iv_splash_lottie)
    LottieAnimationView mLottieView;
    @BindView(R.id.tv_splash_debug)
    View mDebugView;
    @BindView(R.id.tv_splash_name)
    TextView tvSplashName;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_splash;
    }

    @Override
    protected void initEvent() {
        // 设置动画监听
        mLottieView.addAnimatorListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                mDebugView.setVisibility(AppConfig.isDebug() ? View.VISIBLE : View.INVISIBLE);
                mIvSplashView.setVisibility(View.VISIBLE);
                tvSplashName.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                startActivity(HomeActivity.class);
                finish();
            }
        });
        //if (AppConfig.isDebug()) {
        //    mLottieView.removeAllAnimatorListeners();
        //    mLottieView.setVisibility(View.GONE);
        //    startActivity(HomeActivity.class);
        //    finish();
        //}
    }

    @Override
    protected void initData() {
        // TODO: 2020/8/13 在换肤前必须请求到读写手机存储权限，否则换肤会失败
        SkinManager.getInstance().changeSkin(this);
        // 获取用户信息
        //EasyHttp.post(this)
        //        .api(new UserInfoApi())
        //        .request(new HttpCallback<HttpData<UserInfoBean>>(this) {
        //
        //            @Override
        //            public void onSucceed(HttpData<UserInfoBean> data) {
        //
        //            }
        //        });
    }

    @Override
    public ImmersionBar createStatusBarConfig() {
        return super.createStatusBarConfig()
                // 有导航栏的情况下，activity全屏显示，也就是activity最下面被导航栏覆盖，不写默认非全屏
                .fullScreen(true)
                // 隐藏状态栏
                .hideBar(BarHide.FLAG_HIDE_STATUS_BAR)
                // 透明导航栏，不写默认黑色(设置此方法，fullScreen()方法自动为true)
                .transparentNavigationBar();
    }

    @Override
    public void onBackPressed() {
        //禁用返回键
        //super.onBackPressed();
    }

    @Override
    public void onStartChangeSkin() {

    }

    @Override
    public void onChangeSkinError(Exception e) {

    }

    @Override
    public void onChangeSkinComplete() {
        ToastUtils.showShort("换肤成功！");
    }
}